package com.aegis.manage.controller.sys;

import com.aegis.common.mybatis.base.BaseController;
import com.aegis.common.mybatis.model.PageResult;
import com.aegis.manage.api.request.AddPermissionRequest;
import com.aegis.manage.api.request.BindMenuPermissionRequest;
import com.aegis.manage.api.request.BindRoleMenuRequest;
import com.aegis.manage.api.request.BindRolePermissionRequest;
import com.aegis.manage.model.dos.SysPermission;
import com.aegis.manage.service.sys.permission.SysPermissionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Collections;

/**
 * @Author renogo
 *
 * @Version 1.0
 * @Descritube
 */
@RestController
@RequestMapping("/sys/permission")
@Api(tags = "系统-权限管理")
public class SysPermissionController extends BaseController<SysPermissionService> {


    /**
     * 添加权限
     *
     * @param request
     */
    @ApiOperation(value = "添加权限", notes = "添加权限")
    @PostMapping("/add")
    public void addPermission(@RequestBody @Validated AddPermissionRequest request) {
        getService().addPermission(request);
    }


    /**
     * 查询权限分页
     *
     * @param current
     * @param size
     * @return
     */
    @ApiOperation(value = "查询权限分页", notes = "查询权限分页")
    @GetMapping("/page")
    public PageResult<SysPermission> selectPermissionPage(@RequestParam(name = "current", defaultValue = "1") Integer current,
                                                          @RequestParam(name = "current", defaultValue = "10") Integer size) {
        return getService().selectPermissionPage(current, size);
    }

    /**
     * 删除权限
     *
     * @param id
     */
    @ApiOperation(value = "删除权限", notes = "删除权限")
    @DeleteMapping("/{id}")
    public void delPermission(@PathVariable("id") String id) {
        getService().delPermission(Collections.singletonList(id));
    }


    /**
     * @param request
     */
    @ApiOperation(value = "添加角色权限", notes = "添加角色权限")
    @PostMapping("/role")
    public void bindRolePermission(@RequestBody @Validated BindRolePermissionRequest request) {
        getService().bindRolePermission(request.getRoleId(), request.getPermissionIds());
    }

    /**
     * @param request
     */
    @ApiOperation(value = "添加角色菜单", notes = "添加角色菜单")
    @PostMapping("/roleMenu")
    public void bindRoleMenu(@RequestBody @Validated BindRoleMenuRequest request) {
        getService().bindRoleMenu(request.getRoleId(), request.getMenuIds());
    }

    /**
     * @param request
     */
    @ApiOperation(value = "添加菜单权限", notes = "添加菜单权限")
    @PostMapping("/menu")
    public void bindMenuPermission(@RequestBody @Validated BindMenuPermissionRequest request) {
        getService().bindMenuPermission(request.getMenuId(), request.getPermissionIds());
    }




}
